<template>
	<view class="search_result">
		<div class="search">
			<image class="icon" src="/static/search.png" mode=""></image>
			<input class="text" type="text" @confirm='confirm' confirm-type='search' placeholder="搜索科普、资讯">
		</div>
		<div class="tips" v-if='keyword'>搜索到 
		 <text class="name">{{keyword}}</text>
		 相关的结果 
		 <text class="count">{{data.total}}</text>
		  条</div>
		  
		<div class="list_box">
			<div class="item" @click='toDetail(item.id)' v-for="(item,index) in data.list" :key="index">
				<image class="pic"  :src="baseURL+item.image" mode=""></image>
				<div class="desc">{{item.title}}</div>
			</div>
		</div>
	</view>
</template>

<script>
	import { getnewList } from '@/network/api.js'
	import { baseURL } from '@/network/config.js'
	export default {
		data() {
			return {
				data:{
					total:0,
					list:[]
				},
				keyword:'',
				baseURL
			}
		},
		onShow(){
			// #ifdef H5
			document.title = ' '
			// #endif
		},
		onLoad(options){
			// #ifdef H5
			document.title = ' '
			// #endif
			this.getList(options.keyword)
			this.keyword = options.keyword
		},
		methods: {
			confirm(e){
				console.log('val:',e.detail.value)
				this.keyword = e.detail.value
				this.getList(e.detail.value)
			},
			async getList(keywords){
				const { data } = await getnewList({keywords})
				console.log(data)
				this.data = data
			},
			toDetail(id){
				uni.navigateTo({
					url:`/pages/chidai_detail/chidai_detail?id=${id}`
				})
			},
		}
	}
</script>

<style lang="less">
	.search_result{
		padding:10rpx 25rpx;
	}
	.search {
		height: 70rpx;
		background: #EEEEEE;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		flex: 1;
		padding: 0 30rpx;

		.icon {
			width: 35rpx;
			height: 35rpx;
			margin-right: 10rpx;
		}

		.text {
			flex: 1;
			font-size: 25rpx;
			font-weight: 400;
			color: #898989;
		}
	}
	.tips{
		font-size: 24rpx;
		font-weight: 400;
		color: #757575;
		margin-top: 30rpx;
		padding-bottom: 26rpx;
		border-bottom: 1rpx solid #EAEAEA;
		.name{
			color:#4E6FD9;
			margin: 0 10rpx;
		}
		.count{
			color:#C24B4B;
			margin: 0 10rpx;
		}
	}
	.list_box{
		.item{
			display: flex;
			padding: 33rpx 0;
			border-bottom:1px solid #EAEAEA;
			&:last-child{
				border:none;
			}
			.pic{
				width: 340rpx;
				height: 210rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				flex-shrink: 0;
			}
			.desc{
				font-size: 28rpx;
				font-weight: 400;
				color: #444444;
				line-height: 50rpx;
				flex:1;
				margin: 18rpx 0 0 25rpx;
			}
		}
	}
</style>